package com.example.wxminiprogram.controller;

import com.example.wxminiprogram.pojo.Result;
import com.example.wxminiprogram.pojo.Seller;
import com.example.wxminiprogram.service.SellerService;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class SellerController {
    @Autowired
    SellerService sellerService;
    @GetMapping("/api/public/v1/seller/login")
    Result login(@PathParam("account") String account, @PathParam("password") String password){
        Seller seller = this.sellerService.login(account,password);
        if(seller == null){
            //登录失败，账号或密码错误
            return Result.error("登录失败，账号或密码错误");
        }else{
            //登录成功
            return Result.success(seller);
        }
    }
    @GetMapping("/api/public/v1/seller/register")
    Result register(@PathParam("account") String account, @PathParam("password") String password){
        if(this.sellerService.register(account,password)){
            return Result.success("注册成功");
        }else{
            return Result.error("账号已被注册，注册失败");
        }
    }
}
